package com.leapp.sk.viewdelegate.adapter.archives

import android.content.Context
import android.text.TextUtils
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import cc.vv.lkbasecomponent.util.LKScreenUtil
import com.example.mvp.delegate.BaseAdapterDelegate
import com.leapp.sk.R
import com.leapp.sk.bean.BabyAchivesEntity

/**
 * 宝贝档案适配器视图托管类
 * @author  chaohaipeng  on 2018/8/7.
 */
class BabyArchivesAdapterDelegate :BaseAdapterDelegate(){
    override fun getOptionsMenuId(): Int {
        return 0
    }

    override fun initWidget() {
    }

    override fun onDestroy() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.adapter_baby_archives
    }

    /**
     * 设置数据
     */
    fun setData(context: Context,data: BabyAchivesEntity){
        val rl_aba_rootView = getView<RelativeLayout>(R.id.rl_aba_rootView)
        val layoutParams: LinearLayout.LayoutParams? = rl_aba_rootView.layoutParams as LinearLayout.LayoutParams?
        layoutParams?.width=LKScreenUtil.getScreenWidth()
        layoutParams?.height=LKScreenUtil.getScreenWidth()/2
        rl_aba_rootView.layoutParams=layoutParams
        val tv_aba_name = getView<TextView>(R.id.tv_aba_name)
        val tv_aba_sex = getView<TextView>(R.id.tv_aba_sex)
        val tv_aba_brith = getView<TextView>(R.id.tv_aba_brith)
        if (!TextUtils.isEmpty(data.babyName)){
            tv_aba_name.text=data.babyName
        }
        if (!TextUtils.isEmpty(data.babySex)){
            tv_aba_sex.text=context.resources.getString(R.string.string_baby_sex)+data.babySex
        }
        if (!TextUtils.isEmpty(data.babyBirth)){
            tv_aba_brith.text=context.resources.getString(R.string.string_baby_brith)+data.babyBirth
        }
        val iv_aba_class = getView<ImageView>(R.id.iv_aba_class)
        val tv_aba_class_name = getView<TextView>(R.id.tv_aba_class_name)
        if (data.type==1){
            iv_aba_class.setImageResource(R.mipmap.icon_add_class)
            tv_aba_class_name.visibility= View.GONE
        }else{
            iv_aba_class.setImageResource(R.mipmap.icon_change_class)
            tv_aba_class_name.visibility= View.VISIBLE
        }

    }

}